package com.yupi.springbootinit.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    //这里是读取 application.yaml 中的文件存放路径
    @Value("${postFilePath}")
    private String postImgPath;

    @Value("${userFilePath}")
    private String userImgPath;

    @Value("${commentFilePath}")
    private String commentImgPath;

    @Value("${commentRqFilePath}")
    private String commentRqImgPath;

    @Value("${userInfoFilePath}")
    private String userInfoImgPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        WebMvcConfigurer.super.addResourceHandlers(registry);
        registry.addResourceHandler("/postimages/**").addResourceLocations("file:" + postImgPath);
        registry.addResourceHandler("/userimages/**").addResourceLocations("file:" + userImgPath);
        registry.addResourceHandler("/commentimages/**").addResourceLocations("file:" + commentImgPath);
        registry.addResourceHandler("/commentrqimages/**").addResourceLocations("file:" + commentRqImgPath);
        registry.addResourceHandler("/userinfoimages/**").addResourceLocations("file:" + userInfoImgPath);
    }
}